From b4eaf47176ccbf11caaa547ba31311ac59cd09e1 Mon Sep 17 00:00:00 2001 From: oliskoli Date: Thu, 8 May 2008 05:40:36 +0000 Subject: [PATCH] destinator,psp: Fix read of unicode strings on Big Endian hosts. --- destinator.c | 8 ++++---- psp.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/destinator.c b/destinator.c index 59b3c323b..60a71f232 100644 --- a/destinator.c +++ b/destinator.c @@ -60,17 +60,17 @@ gmsd_init(waypoint *wpt) static char * read_wcstr(const int discard) { - short *buff = NULL, c; + gbint16 *buff = NULL, c; int size = 0, pos = 0; - while ((c = gbfgetint16(fin))) { + while (gbfread(&c, sizeof(c), 1, fin) && (c != 0)) { if (size == 0) { size = 16; - buff = xmalloc(size * 2); + buff = xmalloc(size * sizeof(*buff)); } else if (pos == size) { size += 16; - buff = xrealloc(buff, size * 2); + buff = xrealloc(buff, size * sizeof(*buff)); } buff[pos] = c; pos += 1; diff --git a/psp.c b/psp.c index 387536b86..61d37bbc4 100644 --- a/psp.c +++ b/psp.c @@ -77,18 +77,18 @@ psp_write_str(const char *str) static char * psp_read_str(gbfile *fin) { - int i, len; + int len; gbint16 *buff; char *res; len = (unsigned char)gbfgetc(fin); if (len == 0) return NULL; - buff = xmalloc(len * 2); - for (i = 0; i < len; i++) - buff[i] = gbfgetint16(fin); + buff = xmalloc(len * sizeof(*buff)); + gbfread(buff, sizeof(*buff), len, fin); res = cet_str_uni_to_utf8(buff, len); xfree(buff); + return res; } -- 2.30.2